package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.ReferenceProxy;
	import vn.demand.dragon.view.AccountingProjectSearchMediator;
	import vn.demand.dragon.view.ReferenceAccountingListMediator;
	import vn.demand.dragon.view.components.ReferenceAccountingList;
	
	public class OpenReferenceAccountingListCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			if (facade.hasMediator(ReferenceAccountingListMediator.NAME)) {
				TabManager.openTab(ReferenceAccountingList, ReferenceAccountingListMediator.NAME);
				return;
			}
			var ui:ReferenceAccountingList = TabManager.openTab(ReferenceAccountingList, ReferenceAccountingListMediator.NAME) as ReferenceAccountingList;
            facade.registerProxy(new ReferenceProxy(ReferenceProxy.NAME, null));
            
            facade.registerMediator(new ReferenceAccountingListMediator(ui));
            facade.registerMediator(new AccountingProjectSearchMediator(AccountingProjectSearchMediator.NAME, ui.searchForm));
            
            
            var referenceProxy:ReferenceProxy  = facade.retrieveProxy(ReferenceProxy.NAME) as ReferenceProxy;
            referenceProxy.loadReferences();
        }
	}
}